import { useState } from "react";

import MessageContainer from './MessageContainer'

function fetchMessage() {
  return new Promise((resolve, reject) => setTimeout(reject('111111'), 1000));
}

export default function PromiseProp() {
  const [messagePromise, setMessagePromise] = useState(null);
  const [show, setShow] = useState(false);
  const download = () => {
    setMessagePromise(fetchMessage());
    setShow(true);
  }

  if (show) {
    return <MessageContainer messagePromise={messagePromise} />;
  } else {
    return <button onClick={download}>Download message</button>;
  }
}